<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>13canvas图形绘制</title>
</head>
<style>
    canvas {
        border: 1px solid #ccc;
    }
</style>
<body>
<canvas width="600" height="400"></canvas>
<script>
    var myCanvas = document.querySelector('canvas');
    var ctx = myCanvas.getContext('2d');
    /*绘制矩形路径 不是独立路径*/
    ctx.rect(100,100,40,40);
    ctx.fillStyle="#f00";
    ctx.fill();
    /*绘制一个描边矩形，有自己的独立路径*/
    ctx.strokeRect(200,200,20,20);
    /*绘制一个填充矩形*/
    ctx.fillRect(300,300,20,20);
    /*清除矩形的内容 可重新绘制*/
    ctx.clearRect(100,100,10,10)
</script>
</body>
</html>
